<?php

class Cursor implements arrayaccess{
	private $aryData;
	private $intRows;
	private $intIndex;

	public function __construct(){
		$this->intIndex = -1;
	}

	public function initFromArray($array){
		$this->intRows = 1;
		$this->aryData = array($array);
	}

	public function initFromMultilineArray($array){
		if(is_array($array)) {
			$this->intRows = count($array);
			$this->aryData = $array;
		} else {
			$this->intRows = 0;
			$this->aryData = null;
		}
	}

	public function initFromDb($dberg){
		//create data array
		$array = array();
		while($data = mysql_fetch_assoc($dberg)){
			array_push($array, $data);
		}

		$this->initFromMultilineArray($array);
	}

	public function moveToFirst() {
		if($this->intRows > 0) {
			$this->intIndex = 0;
			return true;
		} else {
			return false;
		}
	}

	public function moveToNext() {
		if($this->intIndex+1 < $this->intRows) {
			$this->intIndex = $this->intIndex+1;
			return true;
		} else {
			return false;
		}
	}

	public function moveToLast() {
		if($this->intRows > 0) {
			$this->intIndex = $this->intRows-1;
			return true;
		} else {
			return false;
		}
	}

	public function offsetExists($offset) {
		return isset($this->aryData[$this->intIndex][$offset]);
	}
	
	public function offsetGet($offset){
		return $this->aryData[$this->intIndex][$offset];
	}
	
	public function offsetSet($offset, $value){
		//do nothing
	}

	public function offsetUnset($offset){
		//do nothing
	}
};


?>